package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.common.log.annotation.Log;
import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: BrandController
 * Package: com.atguigu.spzx.manager.controller
 * Description:
 *
 * @Author 刘强
 * @Create 2024/7/5 14:38
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/product/brand")
public class BrandController {
    @Resource
    private BrandService brandService;

    /**
     * 查询所有品牌
     * @return
     */
    @GetMapping("findAll")
    public Result findAll(){
        List<Brand> list =  brandService.findAll();
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        brandService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 根据id修改
     * @param brand
     * @return
     */
    @PutMapping("updateById")
    public Result updateById(@RequestBody Brand brand){
        brandService.updateById(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 新增品牌
     * @param brand
     * @return
     */
    @PostMapping("save")
    public Result save(@RequestBody Brand brand){
        brandService.save(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Log(title = "brand",businessType = 0,isSaveRequestData = false)
    @GetMapping("{pageNum}/{pageSize}")
    public Result page(@PathVariable Integer pageNum,
                       @PathVariable Integer pageSize){
        PageInfo<Brand> page = brandService.page(pageNum,pageSize);
        return Result.build(page, ResultCodeEnum.SUCCESS);
    }
}
